package com.deco.service.clickStatistics;

import com.deco.dao.domain.table.ClickStatistics;
import com.deco.domain.other.EnumPlayType;
import com.deco.domain.other.EnumUrlType;
import com.deco.logic.clickStatistics.ClickStatisticsLogic;
import com.free.common.vo.ResultModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 说明：
 * 创建人：Q879095880
 */
@Service
public class ClickStatisticsService {
    @Autowired
    private ClickStatisticsLogic clickStatisticsLogic;


    public void add(Integer playType,Integer urlType){
        if(urlType == null){
            urlType = EnumUrlType.TM.getKey();
        }
        if(playType == null){
            playType = EnumPlayType.PC.getKey();
        }
        Date now = new Date();
        ClickStatistics clickStatistics = new ClickStatistics();
        clickStatistics.setClickDate(now);
        clickStatistics.setPlayType(playType);
        clickStatistics.setUrlType(urlType);
        List<ClickStatistics> list = clickStatisticsLogic.getByDate(clickStatistics);
        if(list != null && list.size() >0){
            //修改
            clickStatistics.setCount(list.get(0).getCount()+1);
            clickStatisticsLogic.updCount(clickStatistics);
        }else {
            clickStatistics.setCount(1);
            clickStatisticsLogic.add(clickStatistics);
        }
    }
}
